from time import sleep
from tkinter import ttk, scrolledtext
from tkinter import *
from ModeType.Base import BaseOutput

# 重复式输出


class RepeatResult(BaseOutput):
    def createConfig(self, root):
        self.commonConfig(root)
        box = ttk.LabelFrame(root, text='重复式输出配置')
        box.pack(padx=10, pady=10)

        row = 0
        ttk.Label(box, text='内容').grid(row=row, column=0)
        self.strtemp = scrolledtext.ScrolledText(box, height=12)
        self.strtemp.grid(row=row, column=1)
        self.strtemp.insert(INSERT, '请输入内容')

        row += 1
        ttk.Label(box, text='输出次数').grid(row=row, column=0)
        self.count = ttk.Spinbox(box, from_=1, to=10000)
        self.count.grid(row=row, column=1, pady=4, sticky=W+E+N+S)
        self.count.set(10)

        return box

    def run(self):
        index = 0
        count = self.get_count()
        speed = self.get_speed()
        content = self.get_strtemp()
        while index < count:
            if self.stop:
                break
            self.keyResultContent(content)
            index += 1
            sleep(speed)
